local extension = Package("freak_alliance_imperial")
extension.extensionName = "freak_alliance"

Fk:loadTranslationTable{
  ["freak_alliance"] = "怀异集", 
  ["freak_alliance_imperial"] = "怀异集·天极",
  ["fa"] = "怀异",
}

local fa__sunjian = General(extension, "fa__sunjian", "wu", 4,4)

local fa__polu = fk.CreateTriggerSkill{
  name = "fa__polu",
  anim_type = "offensive",
  events = {fk.TargetSpecified},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.card and data.card.trueName == "slash" then
        local to = player.room:getPlayerById(data.to)
        return not to.dead and not player:isNude()
      end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local x = player:getAttackRange()
    local to = room:getPlayerById(data.to)
    local ids = table.filter(player:getCardIds("he"), function(id) return not player:prohibitDiscard(Fk:getCardById(id)) end)
    local ibs = table.filter(to:getCardIds("he"), function(id) return not player:prohibitDiscard(Fk:getCardById(id)) end)
    if #ids + #ibs <= (1 + x) // 2 and #ids <= #ibs then
    local cards = room:askForCardsChosen(player, to, 0, #ids+1, "he", self.name, "#fa__polu-discard::"..data.to)
    if #cards >= 0 then self.cost_data = cards return true end
    else
    local cardsed = room:askForCardsChosen(player, to, 0, (1 + x) // 2, "he", self.name, "#fa__polu-discard::"..data.to)
      if #cardsed >= 0 then self.cost_data = cardsed return true end
    end
  end,
  on_use = function(self, event, target, player, data)
      local room = player.room
      local to = room:getPlayerById(data.to)
      if player.dead or to.dead then return end
      local x = player:getAttackRange()
      if 2 * #self.cost_data > x then
      local cards1 = room:askForCardsChosen(player, player, #self.cost_data - 1, #self.cost_data - 1, "he", self.name)
      room:throwCard(cards1, self.name, player, player)
    elseif 2 * #self.cost_data == x then
      local cards2 = room:askForCardsChosen(player, player, #self.cost_data - 1, #self.cost_data, "he", self.name)
      room:throwCard(cards2, self.name, player, player)
    elseif 2 * #self.cost_data < x then
      local cards3 = room:askForCardsChosen(player, player, #self.cost_data - 1, #self.cost_data + 1, "he", self.name)
      room:throwCard(cards3, self.name, player, player)
      end
      room:throwCard(self.cost_data, self.name, to ,player)
  end,
}

fa__sunjian:addSkill(fa__polu)

Fk:loadTranslationTable{
  ["fa__sunjian"] = "孙坚", 
  ["#fa__sunjian"] = "鸷鹰击浪",
  ["cv:fa__sunjian"] = "天外之音",
  ["illustrator:fa__sunjian"] = "凡果",
  ["designer:fa__sunjian"] = "幽蝶",

  ["fa__polu"] = "破虏",
  [":fa__polu"] = "你使用【杀】指定目标后，你可以弃置你与其共计至多X张牌，且两者弃牌数之差不能大于1。（X为你此时的攻击范围）",
  ["#fa__polu-discard"] = "破虏：你可以选择 %dest 至多你攻击范围一半张牌（若你牌数少于其，则也至多为你牌数+1）。",

  ["$fa__polu1"] = "山河图来，如祝融燃朱天，所往千将无前！",
  ["$fa__polu2"] = "古锭锋至，如共工驭惊滔，所向万寇皆倒！",
  ["~fa__sunjian"] = "恨未见我儿江东小霸王...觉醒啊！",
}

return extension